package cn.edu.tju.scs.leave.web;

import cn.edu.tju.scs.leave.dto.BizCode;
import cn.edu.tju.scs.leave.dto.ResponseCode;
import cn.edu.tju.scs.leave.exception.UserException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * BaseController 异常处理的基类
 * Created by jack on 2016/1/5.
 */
public class BaseController {
    @ExceptionHandler
    public @ResponseBody
    ResponseCode<Object> handleException(Exception ex, HttpServletRequest request,HttpServletResponse response) throws IOException {
        if(ex instanceof UserException){
            return new ResponseCode<Object>(BizCode.FAIL,ex.getMessage());
        }
        return new ResponseCode<Object>(BizCode.FAIL);
    }
}

